package util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class FileUtils {

	//写文件
    public static void writeFile(String fileName, String fileContent)   
    {     
        try   
        {      
            File f = new File(fileName);      
            if (!f.exists())   
            {       
                f.createNewFile();      
            }      
            OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(f),"gbk");      
            BufferedWriter writer=new BufferedWriter(write);          
            writer.write(fileContent);      
            writer.close();     
        } catch (Exception e)   
        {      
            e.printStackTrace();     
        }  
    }  
    
    /**
     * 读文件
     * @param fileName
     * @return
     */
    public static String readFile(String fileName)  
    {     
        String fileContent = "";     
        try   
        {       
            File f = new File(fileName);      
            if(f.isFile()&&f.exists())  
            {       
                InputStreamReader read = new InputStreamReader(new FileInputStream(f),"gbk");       
                BufferedReader reader=new BufferedReader(read);       
                String line;       
                while ((line = reader.readLine()) != null)   
                {        
                    fileContent += line;       
                }         
                read.close();      
            }     
        } catch (Exception e)   
        {         
            e.printStackTrace();     
        }     
        return fileContent;   
    }  
	
}
